/*
* ========== Copyright Header Begin ==========================================
* 
* OpenSPARC T1 Processor File: mem.h
* Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* 
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* 
* The above named program is distributed in the hope that it will be 
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
* 
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* 
* ========== Copyright Header End ============================================
*/
#include "Memory.h"

#ifndef _MEM_H
#define _MEM_H

#pragma ident "@(#)1.16	06/05/22	mem.h"

// old fashion mem methods;
// newer methods from Memory.h where possible should be used instead


typedef SMemory memT;

// a global pointer to mem object, one for the system
extern memT *mm1;


inline caddr_t  membase           (memT *msp)  { return (caddr_t)(msp->get_base()); }
inline uint64_t memsize           (memT *msp)  { return msp->get_size(); }




inline uint64_t memread8s(memT * msp, uint64_t paddr)    { return msp->ld8s(paddr);  }
inline uint64_t memread8u(memT * msp, uint64_t paddr)    { return msp->ld8u(paddr);  }
inline uint64_t memread16s(memT * msp, uint64_t paddr)   { return msp->ld16s(paddr); }
inline uint64_t memread16u(memT * msp, uint64_t paddr)   { return msp->ld16u(paddr); }
inline uint64_t memread32s(memT * msp, uint64_t paddr)   { return msp->ld32s(paddr); }
inline uint64_t memread32u(memT * msp, uint64_t paddr)   { return msp->ld32u(paddr); }
inline uint64_t memread64s(memT * msp, uint64_t paddr)   { return msp->ld64(paddr);  }
inline uint64_t memread64u(memT * msp, uint64_t paddr)   { return msp->ld64(paddr);  }

inline int memread8u_blk_nl (memT * msp, uint64_t paddr, unsigned char *tgt, int n) { return msp->block_read(paddr, tgt, n); }
inline int memwrite8u_blk_nl(memT * msp, uint64_t paddr, const unsigned char *src, int n) { return msp->block_write(paddr, src, n); }
  

inline void memwrite8s(memT * msp, uint64_t paddr, uint64_t value)      { msp->st8(paddr, uint8_t(value));  }
inline void memwrite8s_nl(memT * msp, uint64_t paddr, uint64_t value)   { msp->st8(paddr, uint8_t(value));  }
inline void memwrite8u(memT * msp, uint64_t paddr, uint64_t value)      { msp->st8(paddr, uint8_t(value));  }
inline void memwrite8u_nl(memT * msp, uint64_t paddr, uint64_t value)   { msp->st8(paddr, uint8_t(value));  }
inline void memwrite16s(memT * msp, uint64_t paddr, uint64_t value)     { msp->st16(paddr, uint16_t(value)); }
inline void memwrite16s_nl(memT * msp, uint64_t paddr, uint64_t value)  { msp->st16(paddr, uint16_t(value)); }
inline void memwrite16u(memT * msp, uint64_t paddr, uint64_t value)     { msp->st16(paddr, uint16_t(value)); }
inline void memwrite16u_nl(memT * msp, uint64_t paddr, uint64_t value)  { msp->st16(paddr, uint16_t(value)); }
inline void memwrite32s(memT * msp, uint64_t paddr, uint64_t value)     { msp->st32(paddr, uint32_t(value)); }
inline void memwrite32s_nl(memT * msp, uint64_t paddr, uint64_t value)  { msp->st32(paddr, uint32_t(value)); }
inline void memwrite32u(memT * msp, uint64_t paddr, uint64_t value)     { msp->st32(paddr, uint32_t(value)); }
inline void memwrite32u_nl(memT * msp, uint64_t paddr, uint64_t value)  { msp->st32(paddr, uint32_t(value)); }
inline void memwrite64s(memT * msp, uint64_t paddr, uint64_t value)     { msp->st64(paddr, value); }
inline void memwrite64s_nl(memT * msp, uint64_t paddr, uint64_t value)  { msp->st64_nl(paddr, value); }
inline void memwrite64u(memT * msp, uint64_t paddr, uint64_t value)     { msp->st64(paddr, value); }
inline void memwrite64u_nl(memT * msp, uint64_t paddr, uint64_t value)  { msp->st64_nl(paddr, value); }



inline uint64_t mem_ldstub(memT *msp, uint64_t paddr)                          { return msp->ldstub(paddr); }
inline uint64_t mem_swap(memT *msp, uint64_t paddr, uint64_t value)            { return msp->swap(paddr, uint32_t(value)); }
inline uint64_t mem_cas(memT *msp, uint64_t paddr, uint64_t rs2, uint64_t rd)  { return msp->cas(paddr, uint32_t(rd), uint32_t(rs2));}
inline uint64_t mem_casx(memT *msp, uint64_t paddr, uint64_t rs2, uint64_t rd) { return msp->casx(paddr,rd,rs2); }







#endif /* _MEM_H */
